{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from config import *\n",
    "from map_wrapper import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2020年2月\n"
     ]
    }
   ],
   "source": [
    "print(f'{year}年{month}月')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import sys\n",
    "sys.path.append('../../py')\n",
    "import db\n",
    "import weighted\n",
    "import inspect\n",
    "import matplotlib.pyplot as plt\n",
    "plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签\n",
    "plt.rcParams['axes.unicode_minus']=False #用来正常显示负号\n",
    "%matplotlib inline\n",
    "from mpl_toolkits.basemap import Basemap\n",
    "import seaborn as sns\n",
    "import scipy.stats as stats\n",
    "import numpy as np\n",
    "import math\n",
    "from matplotlib.font_manager import _rebuild\n",
    "\n",
    "_rebuild() #reload一下"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "conn=db.get_conn()\n",
    "data_original=pd.read_sql(sql=f\"select * from _{year}{month:02} where monthly_salary>0 and monthly_salary<80000\", con=conn)\n",
    "error_job_ids=['104660258','104142922','108434795','101357291','106253516','110368302','111391233','108665401','109277048'\n",
    "                  ,'73857191','108584955','102824950','102824949','111391233','110884556']\n",
    "data=data_original[~data_original.job_id.isin(error_job_ids)]\n",
    "\n",
    "del data['publish_date']\n",
    "del data['published_on_weekend']\n",
    "del data['title']\n",
    "del data['company_title']\n",
    "del data['company_description']\n",
    "del data['job_description']\n",
    "del data['job_id']\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "join_counts=[conn.execute(f\"select COUNT(1) from _{year}{month:02}\").fetchall()[0][0]]\n",
    "percents=[]\n",
    "for i in range(1,month-6+1):\n",
    "    sql=f\"select COUNT(1) from _{year}{month:02} a join _{year}{month-i:02} b on a.job_id = b.job_id\"\n",
    "    #print(sql)\n",
    "    count=conn.execute(sql).fetchall()[0][0]\n",
    "\n",
    "    join_counts.append(count)\n",
    "    subtract = join_counts[i-1]-join_counts[i]\n",
    "    percents.append(subtract*1.0/join_counts[i])\n",
    "\n",
    "percents.append(join_counts[-1]/join_counts[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[75336]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "join_counts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1.0]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "percents"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "'label' must be of length 'x'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-9-6279c588f05c>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mpie\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mpercents\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mlabels\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'1'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'2'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'3'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'4'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'5'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'6'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'7'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;34m'7+'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0mplt\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mshow\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\matplotlib\\pyplot.py\u001b[0m in \u001b[0;36mpie\u001b[1;34m(x, explode, labels, colors, autopct, pctdistance, shadow, labeldistance, startangle, radius, counterclock, wedgeprops, textprops, center, frame, rotatelabels, data)\u001b[0m\n\u001b[0;32m   2785\u001b[0m         \u001b[0mwedgeprops\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mwedgeprops\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtextprops\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtextprops\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcenter\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mcenter\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2786\u001b[0m         frame=frame, rotatelabels=rotatelabels, **({\"data\": data} if\n\u001b[1;32m-> 2787\u001b[1;33m         data is not None else {}))\n\u001b[0m\u001b[0;32m   2788\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2789\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\matplotlib\\__init__.py\u001b[0m in \u001b[0;36minner\u001b[1;34m(ax, data, *args, **kwargs)\u001b[0m\n\u001b[0;32m   1599\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0minner\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0max\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mdata\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1600\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mdata\u001b[0m \u001b[1;32mis\u001b[0m \u001b[1;32mNone\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1601\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0max\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0mmap\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msanitize_sequence\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0margs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1602\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1603\u001b[0m         \u001b[0mbound\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mnew_sig\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbind\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0max\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\ProgramData\\Anaconda3\\lib\\site-packages\\matplotlib\\axes\\_axes.py\u001b[0m in \u001b[0;36mpie\u001b[1;34m(self, x, explode, labels, colors, autopct, pctdistance, shadow, labeldistance, startangle, radius, counterclock, wedgeprops, textprops, center, frame, rotatelabels)\u001b[0m\n\u001b[0;32m   2981\u001b[0m             \u001b[0mexplode\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m*\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2982\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlabels\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2983\u001b[1;33m             \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"'label' must be of length 'x'\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2984\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m!=\u001b[0m \u001b[0mlen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mexplode\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2985\u001b[0m             \u001b[1;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"'explode' must be of length 'x'\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mValueError\u001b[0m: 'label' must be of length 'x'"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQUAAAD6CAYAAACoJVLpAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAALZ0lEQVR4nO3bYaidB33H8e9vSYWQdDVll0iHLQTKilOi7lIXTMdtacS+EKHrbEEq6EZwuPq6sogggUGQwnBEvJpBQRnEF3YUKouwhdaSbt4ggVWF+SJFMoLRVLP4Yi/Kfy9yuuR/e+89z72e+9zc8v1A6JOe/zn8e9r7zfOc8zRVhSS96fe2egFJtxajIKkxCpIaoyCpMQqSGqMgqTEKkppBUUiyL8lLazx+W5Lnk7yc5DOzW0/S2KZGIcle4Flg9xpjTwHnqurDwGNJbp/RfpJGtnPAzBvA48A/rzGzADw9OX4RmAf+7eaBJEeAIwC7d+/+k/vuu2+9u0pah3Pnzv2yqubW+7ypUaiqqwBJ1hrbDVycHF8B9q3wOov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b8EfLaqvgz8FPj0SLtt1Lp+zjbzh3C73R49dZfJn77fAb5QVa+Nt9pbDHnfHgY+l+QM8P4k3xxntRUN2fdnwP7J8TywVe/vkF33Au9LsgP4EHCr3+yzvp+zqtqUX8DvA+eBZ7h+inUAODZl5o7N2mdG+/418DpwZvLr8Vt112XzZ7bqfV3He3s714P7InAW+MNbeNf7gVe5/ifw94E9W/n+3vzvGHgI+Jtlj90z2ffvgR9y/YPUVV9rU+9onHwyehh4sa6fFm5oZiy30i7TbKddYXvtu512HWry/yUdAv6lpnwG4W3OkhrvaJTUGAVJjVGQ1BgFSY1RkNT8HwvAF3D5PUx1AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.pie(percents, labels=['1','2','3','4','5','6','7','7+'])\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.shape[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "conn.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Common Functions\n",
    "def get_sub_stats_by_col(data, col):\n",
    "    categories=data[col].unique()\n",
    "    salary_mean=[]\n",
    "    salary_95_min=[]\n",
    "    salary_95_max=[]\n",
    "    salary_median=[]\n",
    "\n",
    "    count=[]\n",
    "    \n",
    "    categorys_out=[]\n",
    "    for category in categories:\n",
    "        #print(feature)\n",
    "        idata=data[data[col]==category]\n",
    "        headcount=idata.headcount.sum()\n",
    "        values = idata.monthly_salary.values\n",
    "        weights = idata.headcount.values\n",
    "        #print(str(headcount))\n",
    "        if headcount==0:\n",
    "            continue\n",
    "        \n",
    "        salary_mean.append(np.average(values, weights=weights))\n",
    "        \n",
    "\n",
    "        q = weighted.weighted_quantile(values,[0.025,0.5,0.975],weights)\n",
    "        salary_95_min.append(q[0])\n",
    "        salary_median.append(q[1])\n",
    "        salary_95_max.append(q[2])\n",
    "        count.append(idata.headcount.sum())\n",
    "        categorys_out.append(category)\n",
    "    sub_data=pd.DataFrame()\n",
    "    sub_data[col]=[c for c in categorys_out]\n",
    "    sub_data['salary_mean']=salary_mean\n",
    "    sub_data['salary_95_min']=salary_95_min\n",
    "    sub_data['salary_median']=salary_median\n",
    "    sub_data['salary_95_max']=salary_95_max\n",
    "    sub_data['head_count']=count\n",
    "    sub_data['percentage']=count/np.sum(count)\n",
    "    sub_data=sub_data.sort_values(by='salary_mean', ascending=False)\n",
    "\n",
    "    return sub_data\n",
    "\n",
    "data_format={\"percentage\":\"{:.2%}\",\"salary_mean\":\"{:.0f}\",\"salary_median\":\"{:.0f}\",\"salary_95_min\":\"{:.0f}\",\"salary_95_max\":\"{:.0f}\"}\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_career=get_sub_stats_by_col(data,'career')\n",
    "data_career.style.format(data_format)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 程序员工资"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_city=get_sub_stats_by_col(data,'province')\n",
    "#data_city.city=data_city.city.map(translate_dict)\n",
    "data_city.style.hide_index().format(data_format)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "describe(data_city,'程序员')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "draw_province_map(data_city,2000,'2019年5月中国大陆各省程序员工资')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 算法工程师"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "describe(get_sub_stats_by_col(data[data.career=='算法工程师'],'province'), '算法工程师')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_city_algorithm=get_sub_stats_by_col(data[data.career=='算法工程师'],'province')\n",
    "\n",
    "data_city_algorithm.style.hide_index().format(data_format)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "describe(data_city_algorithm,'算法工程师')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "draw_province_map(data_city_algorithm,100,f'2019年{month}月中国大陆各省算法工程师工资')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 系统架构师"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_city_architect=get_sub_stats_by_col(data[data.career=='系统架构师'],'province')\n",
    "\n",
    "data_city_architect.style.hide_index().format(data_format)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "describe(data_city_architect,'系统架构师')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "draw_province_map(data_city_architect,40,f'2019年{month}月中国大陆各省【架构师】工资')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 生物信息工程师"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_bio=get_sub_stats_by_col(data[data.career=='生物信息工程师'],'province')\n",
    "#data_bio.city=data_bio.city.map(translate_dict)\n",
    "data_bio.style.hide_index().format(data_format)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "describe(data_bio,'生物信息工程师')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "draw_province_map(data_bio,2,'2019年4月中国大陆各省【生物信息工程师】工资')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 爬虫工程师"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_spider=get_sub_stats_by_col(data[data.career=='爬虫工程师'],'province')\n",
    "\n",
    "\n",
    "data_spider=data_spider[data_spider.head_count>10]\n",
    "data_spider.style.hide_index().format(data_format)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "describe(data_spider, '爬虫工程师')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "draw_province_map(data_spider,5,f'2019年{month}月中国大陆各省【爬虫工程师】工资')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Java程序员"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_java=get_sub_stats_by_col(data[(data.pl_java==1)],'province')\n",
    "data_java.style.hide_index().format(data_format)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "describe(data_java, 'Java程序员')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "draw_province_map(data_java, 500, f'2019年{month}月中国大陆各省【Java工程师】工资')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Python程序员"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data_python=get_sub_stats_by_col(data[(data.pl_python==1)],'province')\n",
    "data_python.style.hide_index().format(data_format)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#describe(data_python, 'Python程序员')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "draw_province_map(data_python, 100,  f'{year}年{month}月中国大陆各省【Python工程师】工资')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
